<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="98px"
    >
      <el-form-item label="仓库名称 " prop="warehouseName">
        <el-input
          v-model="queryParams.warehouseName"
          placeholder="请输入仓库名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库区域" prop="warehouseArea">
        <el-input
          v-model="queryParams.warehouseArea"
          placeholder="请输入仓库区域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料类别：" prop="projectNo">
        <el-input
          v-model="form.projectNo"
          :style="{ width: '100%' }"
          placeholder="物料类别"
        />
      </el-form-item>

      <el-form-item label="物料名称" prop="materialName">
        <el-input
          v-model="queryParams.materialName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="绑定状态" prop="supplierType">
        <el-select
          v-model="queryParams.supplierType"
          placeholder="请选择供应商类型"
          clearable
        >
          <el-option
            v-for="dict in dict.type.binding_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="关联项目" prop="supplierType">
        <el-select
          v-model="queryParams.supplierType"
          placeholder="请选择供应商类型"
          clearable
        >
          <el-option
            v-for="dict in dict.type.binding_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item><br>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['material:WarehouseInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['material:WarehouseInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['material:WarehouseInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['material:WarehouseInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table
      v-loading="loading"
      :data="WarehouseInfoList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="关联项目" align="center" prop="projectNo" />
      <el-table-column label="仓库名称" align="center" prop="warehouseName" />
      <el-table-column label="仓库区域" align="center" prop="warehouseArea" />
      <el-table-column label="物料编号" align="center" prop="materialNo" />
      <el-table-column label="物料名称" align="center" prop="materialName" />
      <el-table-column label="物料类别" align="center" prop="materialType" />
      <el-table-column label="规格" align="center" prop="specifications" />
      <el-table-column label="单位" align="center" prop="unit" />
      <el-table-column
        label="分配数量"
        align="center"
        prop="distributionCount"
      />
      <el-table-column label="剩余数量" align="center" prop="remainderCount" />
      <el-table-column label="期初库存" align="center" prop="initCount" />
      <el-table-column label="安全库存" align="center" prop="secCount" />
      <el-table-column label="最小库存" align="center" prop="minCount" />
      <el-table-column label="最小库存" align="center" prop="maxCount" />
      <el-table-column label="备注" align="center" prop="comment" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['material:WarehouseInfo:edit']"
            >维护</el-button
          >
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['material:WarehouseInfo:remove']"
          >删除</el-button> -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="fenpeiOne(scope.row)"
            v-hasPermi="['material:WarehouseInfo:edit']"
            >分配</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="jiebangOne(scope.row)"
            v-hasPermi="['material:WarehouseInfo:edit']"
            >解绑</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 维护对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <div class="outer">
        <div class="left">
          <el-form ref="form" :model="form" :rules="rules" label-width="100px">
            <el-form-item label="物料类别：" prop="projectNo">
              <el-input
                v-model="form.projectNo"
                :style="{ width: '100%' }"
                placeholder="物料类别"
              />
            </el-form-item>

            <el-form-item label="规格：" prop="projectNo">
              <el-input
                v-model="form.projectNo"
                :style="{ width: '100%' }"
                placeholder="规格："
              />
            </el-form-item>
            <el-row :gutter="25">
              <el-form label-width="70px">
                <el-col :span="30">
                  <el-form-item label="仓库名称" prop="warehouseName">
                    <el-input
                    
                      v-model="form.warehouseName"
                      placeholder="请输入仓库名称"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="30">
                  <el-form-item prop="warehouseArea">
                    <el-input
                      v-model="form.warehouseArea"
                      placeholder="请输入仓库区域"
                    />
                  </el-form-item>
                </el-col>
              </el-form>
            </el-row>

            <el-form-item label="最小库存" prop="minCount">
              <el-input v-model="form.minCount" placeholder="请输入最小库存" />
            </el-form-item>

            <el-form-item label="安全库存" prop="secCount">
              <el-input v-model="form.secCoun" placeholder="请输入安全库存" />
            </el-form-item>
            <el-form-item label="报溢数量" prop="secCount">
              <el-input v-model="form.secCount" placeholder="报溢数量" />
            </el-form-item>
          </el-form>
        </div>
        <div class="right">
          <el-form ref="form" :model="form" :rules="rules" label-width="100px">
            <el-form-item label="物料名称" prop="materialName">
              <el-input
                v-model="form.materialName"
                placeholder="请输入物料名称"
                :style="{ width: '100%' }"
              />
            </el-form-item>
            <el-form-item label="单位" prop="unit">
              <el-input v-model="form.unit" placeholder="请输入单位" />
            </el-form-item>
            <el-form-item label="期初库存" prop="initCount">
              <el-input v-model="form.initCount" placeholder="请输入期初库存" />
            </el-form-item>
            <el-form-item label="最大库存" prop="maxCount">
              <el-input v-model="form.maxCoun" placeholder="请输入最小库存" />
            </el-form-item>
            <el-form-item label="报损数量" prop="maxCount">
              <el-input v-model="form.maxCount" placeholder="请输入最小库存" />
            </el-form-item>
          </el-form>
        </div>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 分配对话框 -->
    <el-dialog :title="title" :visible.sync="fenpei" width="700px" append-to-body>
      <div class="tables">
        



<el-form>
          <h3>分配项目</h3>
          <el-table
            border
            ref="multipleTable"
            tooltip-effect="dark"
            style="width: 100%"
          >
            <!-- <el-table-column type="selection" width="55"> </el-table-column>
            <el-table-column label="序号" prop="id" width="120">
            </el-table-column> -->
            <el-table-column
              prop=""
              label="项目名称"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop=""
              label="分配数量"
              show-overflow-tooltip
            >
            </el-table-column>
            
            

            <el-table-column prop="handle" label="操作" show-overflow-tooltip>
              <template slot-scope="scope">
                <el-row>
  <el-button type="success" icon="el-icon-circle-plus-outline" circle></el-button>
  <el-button type="danger" icon="el-icon-remove-outline" circle></el-button>
</el-row>
              </template>
            </el-table-column>
          </el-table>
        </el-form>


        <div slot="footer" class="dialog-footer" style="margin-top:20px;">
          <el-button @click="fqx">取 消</el-button>
          <el-button type="primary" @click="Fqued">保存</el-button>
        </div>
      </div>
    </el-dialog>

    <!-- 解绑 -->
    <el-dialog :title="title" :visible.sync="jiebang" width="700px" append-to-body>
       <div class="tables">
        



<el-form>
          <h3>分配项目</h3>
          <el-table
            border
            ref="multipleTable"
            tooltip-effect="dark"
            style="width: 100%"
          >
            <!-- <el-table-column type="selection" width="55"> </el-table-column>
            <el-table-column label="序号" prop="id" width="120">
            </el-table-column> -->
            <el-table-column
              prop=""
              label="项目名称"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop=""
              label="分配数量"
              show-overflow-tooltip
            >
            </el-table-column>
            
            

            <el-table-column prop="handle" label="分配数量" show-overflow-tooltip>
            </el-table-column>
          </el-table>
        </el-form>


        <div slot="footer" class="dialog-footer" style="margin-top:20px;">
          <el-button @click="qxjb">取 消</el-button>
          <el-button type="primary" @click="qrjb">确认解绑</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listWarehouseInfo,
  getWarehouseInfo,
  delWarehouseInfo,
  addWarehouseInfo,
  updateWarehouseInfo,
  lossQuantity,
  Distribution,
  Unbound
} from "@/api/material/WarehouseInfo";

export default {
  name: "WarehouseInfo",
  dicts: ["binding_status", "partnership_level"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 库存表格数据
      WarehouseInfoList: [],
      // 弹出层标题
      title: "",
      open: false,
      fenpei:false,
      jiebang:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        warehouseName: null,
        warehouseArea: null,
        materialName: null,
        materialType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询库存列表 */
    getList() {
      this.loading = true;
      listWarehouseInfo(this.queryParams).then((response) => {
        this.WarehouseInfoList = response.dataTable.rows;

        this.total = response.total;
        this.loading = false;
        console.log("res", response.dataTable.rows);
      });
    },
    // 取消按钮
    cancel(){
      this.open = false;
      this.fenpei = false;
      this.jiebang = false;
      this.reset();
    },
    // 分配按钮
    fenpeiOne(){
      this.fenpei = open;
      Distribution(this.queryParams).then(res=>{
        console.log(res)
      })
    },
    jiebangOne(){
this.jiebang = open;
Unbound(this.query).then(res=>{
  console.log(res)
})
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectNo: null,
        warehouseName: null,
        warehouseArea: null,
        materialNo: null,
        materialName: null,
        materialType: null,
        specifications: null,
        unit: null,
        distributionCount: null,
        remainderCount: null,
        initCount: null,
        secCount: null,
        minCount: null,
        maxCount: null,
        createTime: null,
        createBy: null,
        comment: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加库存";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getWarehouseInfo(id).then((response) => {
        this.form = response.data;
        console.log(this.form)
        this.open = true;
        this.title = "库存数量维护";
      });
    },
    qrjb(){
this.jiebang  = false
    },
    qxjb(){
this.jiebang = false
    },

    Fqued(){
this.fenpei = false;
    },
    fqx(){
      this.fenpei = false;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateWarehouseInfo(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.getList();
            });
          } else {
            addWarehouseInfo(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除库存编号为"' + ids + '"的数据项？')
        .then(function () {
          return delWarehouseInfo(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "material/WarehouseInfo/export",
        {
          ...this.queryParams,
        },
        `WarehouseInfo_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>

<style lang="scss" scoped>
.outer {
  width: 100%;
  display: flex;
  .left {
    width: 40%;
  }
  .right {
    width: 40%;
    margin-left: 100px;
  }
}
</style>